home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power Programmierung
/
Power-Programmierung (Tewi)(1994).iso
/
magazine
/
nvdc87
/
julian
/
chrono.tb
< prev
next >
Wrap
Text File
|
1987-05-20
|
2KB
|
89 lines
' CHRONO.TB: Julian Date functions
'
' version: 05-20-87
' compiler: Turbo BASIC v1.0
' uses: nothing
' module type: include file
'
' This file contains functions to work with calendar dates. A
' calendar date is a real number in the format YYMMDD. For
' example, 4/23/87 would be 870423. Julian dates are "magic"
' hashed versions of calendar dates that allow arithmetic,
' determining the day of the week, etc. without consulting an
' actual calendar.
'
' Functions in this file:
'
' FNYear(D) Returns the year part of a calendar date
' FNDay(D) Returns the day part of a calendar date
' FNMonth(D) Returns the month part of a calendar date
' FNJulian(D) Converts a calendar date to a julian date
' FNCalendar(J) Converts a julian date to a calendar date
' FNDayOfWeek(J) Returns day of week for a julian date
' FNToday Returns today's date (from DOS) as calendar
' date
DEF FNYear(Cal)
' Return the year in a calendar date.
FNYear = INT(Cal/10000)
END DEF
DEF FNDay(Cal)
' Return the day in a calendar date.
FNDay = INT(Cal-(INT(Cal/100)*100))
END DEF
DEF FNMonth(Cal)
' Return the month in a calendar date.
FNMonth = INT((Cal-(FNYear(Cal)*10000)-FNDay(Cal))/100)
END DEF
DEF FNJulian(Cal)
' Convert a calendar date into a Julian date
LOCAL m,y
IF FNMonth(Cal) > 2 THEN
m = FNMonth(Cal)+1
y = FNYear(Cal)
ELSE
m = FNMonth(Cal)+13
y = FNYear(Cal)-1
END IF
FNJulian = INT(365.25*(1900+y))+INT(30.6001*m)+FNDay(Cal)+1720982
END DEF
DEF FNCalendar(Jul)
' Convert a Julian date into a calendar date
LOCAL m,d,y,DayNo
DayNo = Jul - 1720982
y = INT((DayNo-122.1)/365.25)
m = INT((DayNo-INT(365.25*y))/30.6001)
d = DayNo-INT(365.25*y)-INT(30.6001*m)
IF m < 14 THEN
m = m-1
ELSE
m = m-13
END IF
IF m < 3 THEN y = y + 1
FNCalendar = (y-1900)*10000 + m*100 + d
END DEF
DEF FNDayOfWeek(Jul)
' Convert Julian date to day of week, 0=Sunday
LOCAL DayNo,X,FracX
DayNo = Jul - 1720982
X = (DayNo+5)/7.0
FracX = X - INT(X)
FNDayOfWeek = INT(7*FracX+0.5)
END DEF
DEF FNToday
' Return today's date as a calendar date from MS DOS
LOCAL m,d,y
REG 1,&H2A00
CALL INTERRUPT &H21
y = REG(3)
m = INT(REG(4)/256)
d = REG(4) AND &H00FF
FNToday = (y-1900)*10000 + m*100 + d
END DEF